package com.wangsiyu.zookeeper.rmi.client;

import com.wangsiyu.zookeeper.rmi.common.HelloService;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;

public class RmiClient {
    public static void main(String[] args) throws MalformedURLException, NotBoundException, RemoteException {
        //定义url
        String url = "rmi://localhost:1099/com.wangsiyu.zookeeper.rmi.server.HelloServiceImpl";
        //寻找发布的服务，并返回对象
        Remote lookup = Naming.lookup(url);
        //强制类型转换
        HelloService helloService = (HelloService)lookup;
        //调用方法
        String result = helloService.sayHello("wangsiyu");
        System.out.println("client result"+result);
        System.out.println(((HelloService) lookup).sayHello("wangsiyu"));
    }
}
